﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QuanLyShop.BUS;
using QuanLyShop.DTO;

namespace SHOP
{
    public partial class TL_GiaBan_ThemGiaMoi : Form
    {
        public TL_GiaBan_ThemGiaMoi()
        {
            InitializeComponent();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        GiaBanDTO gia = new GiaBanDTO();
        private void TL_GiaBan_ThemGiaMoi_Load(object sender, EventArgs e)
        {
            MatHangBUS mh = new MatHangBUS();
            DataTable dt = new DataTable();
            dt = mh.LayDanhSachMatHang();

            cmbLoaiMatHang.DataSource = dt;
            cmbLoaiMatHang.DisplayMembers = "TENMATHANG";
            cmbLoaiMatHang.ValueMember = "ID_MATHANG";

        }

        private void bntThem_Click(object sender, EventArgs e)
        {
            GiaBanBUS BUS = new GiaBanBUS();
            string ID_GiaBan = BUS.MaTangTuDong();
            string TenGiaBan = tbTenGia.Text;
            string GiaTri = tbGia.Text;
            string Kieu = tbKieu.Text;
            string thongtinthem = tbThongTinThem.Text;
            int TinhTrang = 0;
            if (TenGiaBan.Equals("") || GiaTri.Equals("") || Kieu.Equals("") || thongtinthem.Equals(""))
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin");
            }
            else
            {
                string ID_MatHang = cmbLoaiMatHang.SelectedValue.ToString();
                gia.ID_GiaBan = ID_GiaBan;
                gia.TenGiaBan = TenGiaBan;
                gia.GiaTri = GiaTri;
                gia.Kieu = Kieu;
                gia.ThongTinThem = thongtinthem;
                gia.TinhTrang = TinhTrang;
                gia.ID_MatHang = ID_MatHang;
                int kq = BUS.ThemGiaBan(gia);
                if (kq == 1)
                {
                    MessageBox.Show("Thêm Thành Công");
                    TL_GiaBan giaban = new TL_GiaBan();
                    giaban.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Thêm Không Thành Công");
                }
            }

        }
    }
}
